package com.cap.dreamcircle.View.Adapter.Item;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cap.dreamcircle.Common.RecyclerView.BaseItem;
import com.cap.dreamcircle.Consts.Constants;
import com.cap.dreamcircle.Model.Action.KeyboardAction;
import com.cap.dreamcircle.Model.Bean.AdCommentEntity;
import com.cap.dreamcircle.R;
import com.cap.dreamcircle.Utils.GlideUtils;

import de.greenrobot.event.EventBus;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by liucxu on 2017/8/24.
 */

public class AdCommentsItem extends BaseItem<AdCommentEntity> {

    AdCommentEntity commentEntity;
    private CircleImageView comment_author;
    private TextView comment_author_name;
    private TextView comment_cotent;
    private TextView comment_pubish_time;

    public AdCommentsItem(ViewGroup parent) {
        super(parent);
    }

    @Override
    public int getRes() {
        return R.layout.adapter_artical_comments;
    }

    @Override
    public void onCreateView(View rootView) {
        comment_author=(CircleImageView)rootView.findViewById(R.id.comment_author);
        comment_author_name=(TextView)rootView.findViewById(R.id.comment_author_name);
        comment_cotent=(TextView)rootView.findViewById(R.id.comment_cotent);
        comment_pubish_time=(TextView)rootView.findViewById(R.id.comment_pubish_time);
    }

    @Override
    public void onBindView(AdCommentEntity entity) {
        this.commentEntity = entity;
        GlideUtils.getInstance().LoadContextBitmap(getContext(), Constants.BASE_URL + entity.getHeadImgUrl(), comment_author, R.mipmap.default_comment_header, R.mipmap.default_comment_header, GlideUtils.LOAD_BITMAP);
        if(TextUtils.isEmpty(entity.getToUserName())){
            comment_author_name.setText(entity.getNickName());
        }
        else{
            comment_author_name.setText(entity.getNickName()+" 回复 "+entity.getToUserName());
        }
        comment_cotent.setText(entity.getCommentContent());
        comment_pubish_time.setText(entity.getCreateTime());
    }

    @Override
    public void onClick(View v) {
        KeyboardAction action=new KeyboardAction();
        action.toComment=this.commentEntity.getCommentId();
        action.toUserId=this.commentEntity.getFromUserId();
        EventBus.getDefault().post(action);
    }
}
